package com.cqwu.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.servlet.ServletOutputStream;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cqwu.util.BaseAction;

/**
 * @author 黑客LK
 * @time  2015-12-7 下午1:15:10
 * 资源管理Action
 */
@SuppressWarnings("serial")
@Namespace("/test")
@ParentPackage("struts-default")
@Controller
@Scope("prototype")
public class ResourcesMgrAction extends BaseAction{

	@Action(value="readWord",results={})
	public String ReadWord(){
		String filePath = getServletContext().getRealPath("/WEB-INF/upload/git@osc团队开发详解.doc");
		File file = new File(filePath);
		ServletOutputStream out = null;
		try{
			
			getResponse().setContentType("multipart/form-data");
			getResponse().addHeader("Content-Disposition", "inline;filename="+new String(file.getName().getBytes("UTF-8"),"ISO8859-1"));
			getResponse().addHeader("Content-Length", ""+file.length());
			FileInputStream ins = new FileInputStream(file);
			out = getResponse().getOutputStream();
			int b = 0;
			byte[] buffer = new byte[1024];
			while(b!=-1){
				b = ins.read(buffer);
				if(b!=-1)
					out.write(buffer, 0, b);
			}
			ins.close();
			out.close();
			out.flush();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	
}
